﻿using System;
using System.Diagnostics;

namespace Simp.Model.CoreExpressions
{
	/// <summary>Encapsulates a string of characteres as an <see cref="IExpression"/>.</summary>
	/// <remarks>This is a primitive expression, as it doesn't have sub expressions and can't therefore be simplified.</remarks>
	[ExpressionName("String")]
	[ParameterPolicy(0)]
	[DebuggerDisplay("{ExpressionHelper.Serialize(this)}")]
	public class StringExpression : IExpression, IExpressionSerializer
	{
		private readonly string _value;

		/// <summary>Constructor accepting the <see cref="string"/> value.</summary>
		/// <param name="value"></param>
		public StringExpression(string value)
		{
			_value = value;
		}

		/// <summary><see cref="string"/> value encapsulated in this expression.</summary>
		public string Value
		{
			get { return _value; }
		}

		#region IExpressionSerializer Members
		void IExpressionSerializer.Serialize(AppendOnlyStringBuilder builder, params IExpression[] parameters)
		{
			if (builder == null)
			{
				throw new ArgumentNullException("builder");
			}
			if (parameters == null)
			{
				throw new ArgumentNullException("parameters");
			}
			
			builder.Append("\"");
			builder.Append(Value.ToString());
			builder.Append("\"");
		}
		#endregion
	}
}